package co.fitstart.entity.courseware.fitnessgroup;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.DynamicUpdate;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

/**
 * 
 * @author mohanlan
 *
 */
@Entity
@Table(name = "daily_courseware")
@DynamicUpdate
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class DailyCourseware {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 名称 */
    private String name;
    
    /** 顺序 */
    private int sorting;
    
    /** 链接 */
    private String webLink;
    
    /** 教练tips */
    private String coachTips;
    
    /** 类型 动作 or 休息日 */
    @Enumerated(EnumType.ORDINAL)
    private DailyCoursewareType type;
    
    @Enumerated(EnumType.ORDINAL)
    private RoundwareStatus roundwareStatus;
    
    @Enumerated(EnumType.ORDINAL)
    private CoursewareEditStatus editStatus;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
    @JsonIdentityReference(alwaysAsId=true)
    private BatchCourseware batch;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public DailyCourseware() {
    }
    
    /**
     * 
     * @param dailyCoursewareTemplate
     * @param batchCourseware
     */
    public DailyCourseware(DailyCoursewareTemplate dailyCoursewareTemplate, BatchCourseware batchCourseware) {
        this.name = dailyCoursewareTemplate.getName();
        this.sorting = dailyCoursewareTemplate.getSorting();
        this.type = dailyCoursewareTemplate.getType();
        this.roundwareStatus = RoundwareStatus.GROUPED;
        this.editStatus = CoursewareEditStatus.PREPARE;
        this.batch = batchCourseware;
        this.disabled = false;
        
    }
    
    /**
     * 
     * @param dailyCoursewareTemplate
     * @return
     */
    public DailyCourseware edit(DailyCoursewareTemplate dailyCoursewareTemplate) {
        this.name = dailyCoursewareTemplate.getName();
        this.type = dailyCoursewareTemplate.getType();
        return this;
    }
    
    /**
     * 
     * @return
     */
    public DailyCourseware changeType(DailyCoursewareType type) {
        this.type = type;
        return this;
    }
    
    /**
     * 
     * @param roundwareStatus
     * @return
     */
    public DailyCourseware editRoundwareStatus(RoundwareStatus roundwareStatus) {
        this.roundwareStatus = roundwareStatus;
        return this;
    }
    
    /**
     * 
     * @return
     */
    public DailyCourseware editDaily() {
        this.roundwareStatus = RoundwareStatus.READY;
        this.editStatus = CoursewareEditStatus.EDITED;
        return this;
    }
    
    public DailyCourseware link(String tips) {
        if(StringUtils.isNotEmpty(tips)) {
            this.coachTips = tips;
        }
        this.roundwareStatus = RoundwareStatus.FINISH;
        this.editStatus = CoursewareEditStatus.GENERATED;
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the sorting
     */
    public int getSorting() {
        return sorting;
    }

    /**
     * @return the webLink
     */
    public String getWebLink() {
        return webLink;
    }

    /**
     * @return the coachTips
     */
    public String getCoachTips() {
        return coachTips;
    }

    /**
     * @return the type
     */
    public DailyCoursewareType getType() {
        return type;
    }

    /**
     * @return the roundwareStatus
     */
    public RoundwareStatus getRoundwareStatus() {
        return roundwareStatus;
    }

    /**
     * @return the editStatus
     */
    public CoursewareEditStatus getEditStatus() {
        return editStatus;
    }

    /**
     * @return the batch
     */
    public BatchCourseware getBatch() {
        return batch;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param sorting the sorting to set
     */
    public void setSorting(int sorting) {
        this.sorting = sorting;
    }

    /**
     * @param webLink the webLink to set
     */
    public void setWebLink(String webLink) {
        this.webLink = webLink;
    }

    /**
     * @param coachTips the coachTips to set
     */
    public void setCoachTips(String coachTips) {
        this.coachTips = coachTips;
    }

    /**
     * @param type the type to set
     */
    public void setType(DailyCoursewareType type) {
        this.type = type;
    }

    /**
     * @param roundwareStatus the roundwareStatus to set
     */
    public void setRoundwareStatus(RoundwareStatus roundwareStatus) {
        this.roundwareStatus = roundwareStatus;
    }

    /**
     * @param editStatus the editStatus to set
     */
    public void setEditStatus(CoursewareEditStatus editStatus) {
        this.editStatus = editStatus;
    }

    /**
     * @param batch the batch to set
     */
    public void setBatch(BatchCourseware batch) {
        this.batch = batch;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
}
